package com.ruoyi.gxdj.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.ruoyi.common.core.domain.entity.SysUser;
import com.ruoyi.system.service.ISysUserService;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.gxdj.domain.InfoVideo;
import com.ruoyi.gxdj.service.IInfoVideoService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 视频Controller
 * 
 * @author ruoyi
 * @date 2024-03-16
 */
@RestController
@RequestMapping("/InfoVideo/video")
public class InfoVideoController extends BaseController
{
    @Autowired
    private IInfoVideoService infoVideoService;

    @Autowired
    private ISysUserService userService;

    /**
     * 查询视频列表
     */
    @GetMapping("/list")
    public TableDataInfo list(InfoVideo infoVideo)
    {
        startPage();
        List<InfoVideo> list = infoVideoService.selectInfoVideoList(infoVideo);
        for (InfoVideo video : list) {
            SysUser user = userService.selectUserById(video.getUserId());
            video.setNickName(user.getNickName());
        }
        return getDataTable(list);
    }

    /**
     * 导出视频列表
     */
    @Log(title = "视频", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, InfoVideo infoVideo)
    {
        List<InfoVideo> list = infoVideoService.selectInfoVideoList(infoVideo);
        ExcelUtil<InfoVideo> util = new ExcelUtil<InfoVideo>(InfoVideo.class);
        util.exportExcel(response, list, "视频数据");
    }

    /**
     * 获取视频详细信息
     */
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(infoVideoService.selectInfoVideoById(id));
    }

    /**
     * 新增视频
     */
    @Log(title = "视频", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody InfoVideo infoVideo)
    {
        return toAjax(infoVideoService.insertInfoVideo(infoVideo));
    }

    /**
     * 修改视频
     */
    @Log(title = "视频", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody InfoVideo infoVideo)
    {
        return toAjax(infoVideoService.updateInfoVideo(infoVideo));
    }

    /**
     * 删除视频
     */
    @Log(title = "视频", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(infoVideoService.deleteInfoVideoByIds(ids));
    }
}
